<script setup>
import { ref, onMounted, computed } from 'vue';
import * as admin from '@/api/indexdata.js';
import { useRouter } from 'vue-router';

const router = useRouter();

// 景点列表数据
const jinquList = ref([]);
const total = ref(0);
const currentPage = ref(1);
const pageSize = 10;

// 行政区列表及选中值
const districts = [
  '市南区', '市北区', '黄岛区', '崂山区',
  '李沧区', '城阳区', '即墨区', '胶州市',
  '平度市', '莱西市'
];
const selectedDistrict = ref('');

// 获取酒店列表数据
const finjiudian = async () => {
  const params = { 
    currentPage: currentPage.value,
    district: selectedDistrict.value
  };
  const res = await admin.articleJiudianListService(params);
  console.log(res);
  total.value = res.total;
  jinquList.value = res.data || [];
};

// 分页数据计算
const currentPageData = computed(() => {
  if (Array.isArray(jinquList.value) && jinquList.value.length > 0) {
    const start = (currentPage.value - 1) * pageSize;
    const end = currentPage.value * pageSize;
    return jinquList.value.slice(start, end);
  }
  return [];
});

// 日期格式化
const formatDate = (dateString) => {
  if (!dateString) return '暂无数据';
  const date = new Date(dateString);
  return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
};

// 分页切换
const handlePageChange = (page) => {
  currentPage.value = page;
  finjiudian();
};

// 行政区变更
const handleDistrictChange = () => {
  currentPage.value = 1;
  finjiudian();
};

// 路由跳转
const goToJinquData = (id) => {
  router.push({ path: '/indexJiudianData', query: { JiudianId: id } });
};

const goToJindianList = (id) => {
  router.push({ path: '/indexJindianList', query: { JiudianId: id } });
};

// 加载数据
onMounted(() => {
  finjiudian();
});
</script>

<template>
  <el-main>
    <!-- 行政区筛选 -->
    <el-row :gutter="20" justify="center" style="margin-bottom: 20px;">
      <el-col :span="16">
        <el-select
          v-model="selectedDistrict"
          placeholder="请选择行政区"
          @change="handleDistrictChange"
          clearable
          class="highlighted-select"
          style="width: 100%;"
        >
          <el-option
            v-for="district in districts"
            :key="district"
            :label="district"
            :value="district"
          />
        </el-select>


      </el-col>
    </el-row>

    <!-- 酒店列表 -->
    <el-row :gutter="20" justify="center">
      <el-col :span="16" v-for="(item, index) in jinquList" :key="item.id">
        <el-card :body-style="{ padding: '20px' }">
          <div>
            <el-image
              v-if="item.img"
              :src="item.img"
              alt="酒店图片"
              fit="cover"
              style="width: 100%; height: 200px; border-radius: 8px;">
            </el-image>
            
            <h3>{{ item.name }}</h3>
            <p>{{ item.description }}</p>
            <p><strong>地址：</strong>{{ item.address }}</p>
            <p><strong>行政区：</strong>{{ item.district || '未知' }}</p>
            <p><strong>类型：</strong><el-tag class="ml-2" type="warning">{{ item.type }}</el-tag></p>
            <p><strong>联系电话：</strong>{{ item.photo }}</p>
            <p><strong>价格：</strong>{{ item.price }}</p>
            <p><strong>评分：</strong><el-rate v-model="item.rating" clearable disabled /></p>
            <p><strong>创建时间：</strong>{{ formatDate(item.createTime) }}</p>
            <p>
              <el-button type="primary" @click="goToJinquData(item.id)">预约酒店</el-button>
              <!-- <el-button type="success" @click="goToJindianList(item.id)">查看景点</el-button> -->
            </p>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 分页组件 -->
    <div style="display: flex; justify-content: center; margin-top: 20px;">
      <el-pagination 
        :current-page="currentPage"
        :page-size="pageSize"
        :total="total"
        @current-change="handlePageChange"
        layout="prev, pager, next, jumper">
      </el-pagination>
    </div>
  </el-main>
</template>

<style scoped>
.el-container {
  height: 100vh;
}

.el-header {
  background-color: #409eff;
  color: white;
  text-align: center;
  padding: 10px;
}

.el-main {
  padding: 20px;
}

.el-footer {
  text-align: center;
  background-color: #f4f4f4;
  padding: 10px;
}

.el-card {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.el-card h3 {
  font-size: 20px;
  color: #409eff;
}

.el-card p {
  font-size: 14px;
  color: #666;
}








.highlighted-select {
  border-radius: 12px;
  font-size: 16px;
  font-weight: bold;
  background-color: #f5faff;
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
  transition: all 0.3s ease;
}

.highlighted-select .el-input__wrapper {
  border: 2px solid #409eff !important;
  border-radius: 12px !important;
  padding: 10px 14px;
  background-color: #ffffff !important;
}

.highlighted-select .el-input__inner {
  font-size: 16px;
  color: #333;
}

.highlighted-select:hover .el-input__wrapper {
  box-shadow: 0 6px 20px rgba(64, 158, 255, 0.4);
  background-color: #eef6ff !important;
}


</style>
